<template>
  <div>
    <van-nav-bar
      title="我的帖子"
      left-text=""
      left-arrow
      @click-left="onClickLeft"
    >
    </van-nav-bar>
    <!-- 下面的帖子内容 -->
    <div class="selfInfo" v-for="(item, index) in checkPostList" :key="index">
      <router-link
        :to="{
          path: '/postDetail',
          query: { postsId: item.postsId },
        }"
      >
        <div class="infoTitle">
          <span>{{ item.title }}</span>
          <!-- <span class="postTime"></span> -->
        </div>
        <div class="infoTopPic">
          <img :src="item.avatar" alt="" />
        </div>
        <div class="infoName">
          <span style="padding-top: 4px">{{ item.userName }}</span>
          <p class="infoTime" style="margin: 0; padding-top: 4px">
            {{ item.sendTime }}
          </p>
        </div>
        <!-- 发表的内容名 -->
        <div class="postListContent">
          {{ item.intro }}
        </div>
        <div class="listPic">
          <img :src="item.coverImgUrl" alt="" />
        </div>
      </router-link>
    </div>

    <!--  -->
  </div>
</template>

<script>
import { Toast } from "vant";
import { checkPost, } from "../api/api";

export default {
  name: "MinePost",
  components: {},
  data() {
    return {
      // postList: {},
      checkPostList: {},
      newObj: [],
    };
  },
  methods: {
    onClickLeft() {
      Toast("返回");
      window.history.back(-1);
    },

  },
  created() {
    // postList().then((res) => {
    //   console.log(res);
    //   if (res.code == 0) {
    //     this.postList = res.rows;
    //   }
    // });
    // 我发表过的帖子
   
    checkPost().then((res) => {
      for (let i = 0; i < res.rows.length; i++) {
        if (res.rows[i].userId == this.$store.state.userInfo.userId) {
          console.log(this.newObj.push(res.rows[i]));
          console.log(this.newObj);
          this.checkPostList = this.newObj;
          this.checkPostList.reverse()
        }
      }
    });
  },
};
</script>

<style  scoped lang="less">
/deep/.van-nav-bar__content {
  background-color: #cc0000;
}
/deep/.van-nav-bar .van-icon {
  color: #fff;
}
/deep/.van-nav-bar__text {
  color: #fff;
}
/deep/.van-nav-bar__title {
  color: #fff;
}
/deep/.van-button--info {
  background-color: #cc0000;
  border: 1px solid #cc0000;
}
// 下面的信息
.selfInfo {
  margin: auto;
  margin-top: 5%;
  width: 100%;
  /* height: 350px;  */
  /* border: 1px solid red;  */
  background-color: #eee;
}
.infoTitle {
  margin: 20px 0 10px 20px;
  /* width: 100px; */
  height: 34px;
  line-height: 34px;
  text-align: left;
  font-size: 20px;
  color: black;

  /* border: 1px solid black; */
}

.infoTopPic {
  float: left;
  margin-top: 10px;
  margin-left: 20px;
  width: 40px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  /* border: 1px solid blue; */
  border-radius: 20px;
  color: black;
}
.infoTopPic > img {
  width: 40px;
  height: 40px;
  border-radius: 20px;
}
.infoName {
  margin-left: 60px;
  margin-top: 20px;
  padding-left: 10px;
  /* width: 140px; */
  /* height: 20px; */
  vertical-align: middle;
  font-size: 12px;
  text-align: left;
  color: black;
}
.postListContent {
  margin: 7% 0 2% 8%;
  width: 80%;
  text-align: left;
  color: black;

  /* text-indent: 2em; */
}
.listPic {
  margin: auto;
  width: 82%;
}
.listPic > img {
  width: 50%;
}
</style>